package com.ztjc.day03_listview;

import android.app.Activity;
import android.os.Bundle;
import android.widget.ListView;

import com.ztjc.day03_listview.adapter.FriendAdapter;
import com.ztjc.day03_listview.domain.Person;

import java.util.ArrayList;
import java.util.List;

/**
 * Android中ListView的使用
 */
public class MainActivity extends Activity {

    private ListView lvFriend;
    private int[] icons = {R.drawable.head_1, R.drawable.head_2, R.drawable.head_3, R.drawable.head_4};
    private List<Person> persons;
    private FriendAdapter adapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        lvFriend = (ListView) findViewById(R.id.lv_friend);

        createData();
    }

    /**
     * 创建虚拟的数据
     */
    private void createData() {
        persons = new ArrayList<>();
        for (int i = 0; i < 20; i ++) {
            persons.add(new Person(icons[i & 3], "小三" + i));
        }
        adapter = new FriendAdapter(this, persons);
        lvFriend.setAdapter(adapter);
    }

}
